package com.lm.location.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import main.java.org.dss.lm.admin.connection.DatabaseConnection;
import com.lm.location.action.*;


public class LocationDao{
	
	DatabaseConnection lmDB = new DatabaseConnection();
    Connection con;
    
	ResultSet rs;
	PreparedStatement ps;  
	
	public void saveNewLocation(Location loc){
		int count=0;
		String selectquery = "SELECT * FROM location";
				try {
					//Connection conn = ConnMngt.getConnection();
					con=lmDB.getDBConnection();
					ps = con.prepareStatement(selectquery);			
					rs = ps.executeQuery();
					count = rs.getFetchSize();
					ArrayList<String> locID = new ArrayList<String>();
					System.out.println("Query is: "+selectquery);
					while(rs.next()){
						locID.add(rs.getString(1));
						}
					count = locID.size()+1;
				} catch (SQLException e) {
					e.printStackTrace();
				}	
		
		System.out.println(loc.getName());
		System.out.println(loc.getLocationCode());
			String query = "INSERT INTO location ( LocationID, LocationCode, Name, Category, Address, Block, District, State, Country, LandArea, LandTerm, LandType, RunningFeet, CoveredArea, RegisteredOnName,RegistrationNo, " +
					"RegistrationDate, SubRegistrar, EstimatedValue, StampExpenditure, OtherExpenditure, RegistryHolder, RegistryCopy, BuildingMap, Canteen, Landmark, DistanceFromMainRoad, ResponsiblePerson, Status, TotalBalance) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 
		try {		
			
			con=lmDB.getDBConnection();
			double locCode = count+1;
			
			ps = con.prepareStatement(query);
			ps.setString(1, Double.toString(locCode));
			ps.setString(2, loc.getLocationCode());
			ps.setString(3, loc.getName());
			ps.setString(4, loc.getCategory());
			ps.setString(5, loc.getAddress());
			ps.setString(6, loc.getBlock());
			ps.setString(7, loc.getDistrict());
			ps.setString(8, loc.getState());
			ps.setString(9, loc.getCountry());
			ps.setString(10, loc.getLandarea());
			ps.setString(11, loc.getLandterm());
			ps.setString(12, loc.getLandtype());
			ps.setDouble(13, loc.getRunningft());
			ps.setString(14, loc.getCoveredarea());
			ps.setString(15, loc.getRegisteredname());
			ps.setString(16, loc.getRegisterationno());
			ps.setDate(17, java.sql.Date.valueOf("2012-01-25"));
			ps.setString(18, loc.getSubregistrar());
			ps.setDouble(19, loc.getEstvalue());
			ps.setDouble(20, loc.getStmpexp());
			ps.setDouble(21, loc.getOtherexp());
			ps.setString(22, loc.getRegholder());
			ps.setString(23, loc.getRegcopy());
			ps.setString(24, loc.getBuildingmap());
			ps.setString(25, loc.getCanteenOption());
			ps.setString(26,loc.getLndmark());
			ps.setString(27, loc.getDistance());
			ps.setString(28, loc.getResponsible());
			ps.setString(29, loc.getStatus());
			ps.setDouble(30, loc.getBalance());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try{
				if(ps!=null)
					ps.close();			
				if(con!=null)
					con.close();
				}
			catch(SQLException ee){				
			}
		}
		//sachin implement below everywhere
		//finally{try{if(pst1!=null)pst1.close();if(rs1!=null)rs1.close();if(pst2!=null)pst2.close();if(rs2!=null)rs2.close();if(con!=null)con.close();}catch(SQLException ee){}}
	}
	
	public void updateLocation(Location loc){
		//String query1 = "UPDATE ACCOUNT SET Amount=?, Reason=?, ItemPurchased=?, InterestAmount=?, PersonID=?, Narration=?, TransactionType=?, ModeOfPayment=?, TransactionAuthorizerID=?, Status=?,  TransactionDate=?, ReturnDate=?, LocationID=? WHERE FormID=?";
		String query = "UPDATE LOCATION SET Name=?, Category=?, Address=?, Block=?, District=?, State=?, Country=?, LandArea=?, LandTerm=?, LandType=?, RunningFeet=?, CoveredArea=?, RegisteredOnName=?,RegistrationNo=?, " +
				"RegistrationDate=?, SubRegistrar=?, EstimatedValue=?, StampExpenditure=?, OtherExpenditure=?, RegistryHolder=?, RegistryCopy=?, BuildingMap=?, Canteen=?, Landmark=?, DistanceFromMainRoad=?, ResponsiblePerson=?, Status=?, TotalBalance=?, LocationCode=? WHERE LocationID=?"; 
	try {		
		con=lmDB.getDBConnection();
		ps = con.prepareStatement(query);
		ps.setString(1, loc.getName());
		ps.setString(2, loc.getCategory());
		ps.setString(3, loc.getAddress());
		ps.setString(4, loc.getBlock());
		ps.setString(5, loc.getDistrict());
		ps.setString(6, loc.getState());
		ps.setString(7, loc.getCountry());
		ps.setString(8, loc.getLandarea());
		ps.setString(9, loc.getLandterm());
		ps.setString(10, loc.getLandtype());
		ps.setDouble(11, loc.getRunningft());
		ps.setString(12, loc.getCoveredarea());
		ps.setString(13, loc.getRegisteredname());
		ps.setString(14, loc.getRegisterationno());
		ps.setDate(15, java.sql.Date.valueOf("2012-01-25"));
		ps.setString(16, loc.getSubregistrar());
		ps.setDouble(17, loc.getEstvalue());
		ps.setDouble(18, loc.getStmpexp());
		ps.setDouble(19, loc.getOtherexp());
		ps.setString(20, loc.getRegholder());
		ps.setString(21, loc.getRegcopy());
		ps.setString(22, loc.getBuildingmap());
		ps.setString(23, loc.getCanteenOption());
		ps.setString(24, loc.getLndmark());
		ps.setString(25, loc.getDistance());
		ps.setString(26, loc.getResponsible());
		ps.setString(27, loc.getStatus());
		ps.setDouble(28, loc.getBalance());
		ps.setString(29, loc.getLocationCode());
		ps.setString(30, loc.getLocationID()); 
		
		ps.executeUpdate();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally{
		try{
			if(ps!=null)
				ps.close();			
			if(con!=null)
				con.close();
			}
		catch(SQLException ee){				
		}
	}		
}
	
	public List searchLocation(Location loc){
		List locList = new ArrayList();
		Location location;
		String query1 = getWhereClause(loc);
		
		String query = "SELECT LocationID, LocationCode, Name, Category, Address, Block, District, State, Country, LandArea, LandTerm, LandType, RunningFeet, CoveredArea, RegisteredOnName,RegistrationNo, " +
					"RegistrationDate, SubRegistrar, EstimatedValue, StampExpenditure, OtherExpenditure, RegistryHolder, RegistryCopy, BuildingMap, Canteen, Landmark, DistanceFromMainRoad, ResponsiblePerson, Status, TotalBalance FROM location where "+" "+query1+" AND Status='Approved'";
		try {
			con=lmDB.getDBConnection();
			ps = con.prepareStatement(query);			
			rs = ps.executeQuery();
			while(rs.next()){
				location = new Location();
				location.setLocationID(rs.getString(1));
				location.setLocationCode(rs.getString(2));
				location.setName(rs.getString(3));
				location.setCategory(rs.getString(4));
				location.setAddress(rs.getString(5));
				location.setBlock(rs.getString(6));
				location.setDistrict(rs.getString(7));
				location.setState(rs.getString(8));
				location.setCountry(rs.getString(9));
				location.setLandarea(rs.getString(10));
				location.setLandterm(rs.getString(11));
				location.setLandtype(rs.getString(12));
				location.setRunningft(rs.getDouble(13));
				location.setCoveredarea(rs.getString(14));
				location.setRegisteredname(rs.getString(15));
				location.setRegisterationno(rs.getString(16));
				location.setRegistereddate(rs.getDate(17).toString());
				location.setSubregistrar(rs.getString(18));
				location.setEstvalue(rs.getDouble(19));
				location.setStmpexp(rs.getDouble(20));
				location.setOtherexp(rs.getDouble(21));
				location.setRegholder(rs.getString(22));
				location.setRegcopy(rs.getString(23));
				location.setBuildingmap(rs.getString(24));
				location.setCanteenOption(rs.getString(25));
				location.setLndmark(rs.getString(26));
				location.setDistance(rs.getString(27));
				location.setResponsible(rs.getString(28));
				location.setStatus(rs.getString(29));
				location.setBalance(rs.getDouble(30));
				locList.add(location);
			}
			System.out.println("Query is: "+query);
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try{
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();				
				if(con!=null)
					con.close();
				}
			catch(SQLException ee){				
			}
		}			
		return locList;
	}
	
	public String getWhereClause(Location loc){
		Map<String,String> mapString = new HashMap<String, String>();
		Map<String,String> mapInt = new HashMap<String, String>();
		mapInt.put("LOCATIONCODE", loc.getLocationCode());
		mapString.put("name", loc.getName());
		mapString.put("category", loc.getCategory());
		mapString.put("block", loc.getBlock());
		mapString.put("district", loc.getDistrict());
		mapString.put("state", loc.getState());
		mapString.put("country", loc.getCountry());
		String whereQuery="";
		
		Set setInteger = mapInt.entrySet(); 
		Iterator j = setInteger.iterator(); 
			while(j.hasNext()) {  
			Map.Entry me = (Map.Entry)j.next(); 
			System.out.print("Key: "+me.getKey() + ": ");
				if((!("".equals(me.getValue().toString().trim()))) && me.getValue()!=null){
					
					whereQuery=whereQuery+me.getKey()+"="+me.getValue();
					whereQuery=whereQuery+" AND ";
				}
			
			System.out.println("Its Value: "+me.getValue()); 
			}
		
		Set set = mapString.entrySet(); 
		Iterator i = set.iterator(); 
			while(i.hasNext()) { 
				Map.Entry me = (Map.Entry)i.next(); 
					if((!("".equals(me.getValue().toString().trim()))) && me.getValue()!=null){
						whereQuery=whereQuery+me.getKey()+"= '"+me.getValue()+"'";;
						whereQuery=whereQuery+" AND ";
					}
			}
		whereQuery=whereQuery.substring(0, (whereQuery.length()-4));
		return whereQuery;
	}

	
	public void deleteLocation(String locID){
		//String locCode=loc.getLocationID();
		String query = "UPDATE LOCATION SET Status=? WHERE LocationID="+locID; 
	try {		
		con=lmDB.getDBConnection();
		ps = con.prepareStatement(query);
		ps.setString(1, "Rejected");
		ps.executeUpdate();
	} catch (SQLException e) {
		e.printStackTrace();
	}		
}
	
	public void approveLocation(String locID){
		//String locCode=loc.getLocationID();
		String query = "UPDATE LOCATION SET Status=? WHERE LocationID="+locID; 
	try {		
		con=lmDB.getDBConnection();
		ps = con.prepareStatement(query);
		ps.setString(1, "Approved");
		ps.executeUpdate();
	} catch (SQLException e) {
		e.printStackTrace();
	}		
}
	
	public Location viewLocation(String locID){

		Location location = null;
		List locList = new ArrayList();
		String queryGetLocationToedit = "SELECT LocationID, LocationCode, Name, Category, Address, Block, District, State, Country, LandArea, LandTerm, LandType, RunningFeet, CoveredArea, RegisteredOnName,RegistrationNo, " +
				"RegistrationDate, SubRegistrar, EstimatedValue, StampExpenditure, OtherExpenditure, RegistryHolder, RegistryCopy, BuildingMap, Canteen, Landmark, DistanceFromMainRoad, ResponsiblePerson, Status, TotalBalance FROM location where "+" LocationID="+locID;
		try{
			con=lmDB.getDBConnection();
		ps = con.prepareStatement(queryGetLocationToedit);			
		rs = ps.executeQuery();
		while(rs.next()){
			location = new Location();
			location.setLocationID(rs.getString(1));
			location.setLocationCode(rs.getString(2));
			location.setName(rs.getString(3));
			location.setCategory(rs.getString(4));
			location.setAddress(rs.getString(5));
			location.setBlock(rs.getString(6));
			location.setDistrict(rs.getString(7));
			location.setState(rs.getString(8));
			location.setCountry(rs.getString(9));
			location.setLandarea(rs.getString(10));
			location.setLandterm(rs.getString(11));
			location.setLandtype(rs.getString(12));
			location.setRunningft(rs.getDouble(13));
			location.setCoveredarea(rs.getString(14));
			location.setRegisteredname(rs.getString(15));
			location.setRegisterationno(rs.getString(16));
			location.setRegistereddate("2012-12-10");
			location.setSubregistrar(rs.getString(18));
			location.setEstvalue(rs.getDouble(19));
			location.setStmpexp(rs.getDouble(20));
			location.setOtherexp(rs.getDouble(21));
			location.setRegholder(rs.getString(22));
			location.setRegcopy(rs.getString(23));
			location.setBuildingmap(rs.getString(24));
			location.setCanteenOption(rs.getString(25));
			location.setLndmark(rs.getString(26));
			location.setDistance(rs.getString(27));
			location.setResponsible(rs.getString(28));
			location.setStatus(rs.getString(29));
			location.setBalance(rs.getDouble(30));
			locList.add(location);
		}
		System.out.println("Query is: "+queryGetLocationToedit);
	} catch (SQLException e) {
		e.printStackTrace();
	}			
	
		return location;		
	
		
		
		
		/*
		//String locCode=loc.getLocationID();
		String query = "SELECT * FROM LOCATION WHERE LocationID="+locID + " AND  Status=? "; 
	try {		
		Connection conn = ConnMngt.getConnection();
		ps = conn.prepareStatement(query);
		ps.setString(1, "Approved");
		ps.executeUpdate();
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	} catch (SQLException e) {
		e.printStackTrace();
	}		
*/}
	
	public Location getlocationToEdit(String locID){
		Location location = null;
		List locList = new ArrayList();
		String queryGetLocationToedit = "SELECT LocationID, LocationCode, Name, Category, Address, Block, District, State, Country, LandArea, LandTerm, LandType, RunningFeet, CoveredArea, RegisteredOnName,RegistrationNo, " +
				"RegistrationDate, SubRegistrar, EstimatedValue, StampExpenditure, OtherExpenditure, RegistryHolder, RegistryCopy, BuildingMap, Canteen, Landmark, DistanceFromMainRoad, ResponsiblePerson, Status, TotalBalance FROM location where "+" LocationID="+locID;
		try{
			con=lmDB.getDBConnection();
		ps = con.prepareStatement(queryGetLocationToedit);			
		rs = ps.executeQuery();
		while(rs.next()){
			location = new Location();
			location.setLocationID(rs.getString(1));
			location.setLocationCode(rs.getString(2));
			location.setName(rs.getString(3));
			location.setCategory(rs.getString(4));
			location.setAddress(rs.getString(5));
			location.setBlock(rs.getString(6));
			location.setDistrict(rs.getString(7));
			location.setState(rs.getString(8));
			location.setCountry(rs.getString(9));
			location.setLandarea(rs.getString(10));
			location.setLandterm(rs.getString(11));
			location.setLandtype(rs.getString(12));
			location.setRunningft(rs.getDouble(13));
			location.setCoveredarea(rs.getString(14));
			location.setRegisteredname(rs.getString(15));
			location.setRegisterationno(rs.getString(16));
			location.setRegistereddate("2012-12-10");
			location.setSubregistrar(rs.getString(18));
			location.setEstvalue(rs.getDouble(19));
			location.setStmpexp(rs.getDouble(20));
			location.setOtherexp(rs.getDouble(21));
			location.setRegholder(rs.getString(22));
			location.setRegcopy(rs.getString(23));
			location.setBuildingmap(rs.getString(24));
			location.setCanteenOption(rs.getString(25));
			location.setLndmark(rs.getString(26));
			location.setDistance(rs.getString(27));
			location.setResponsible(rs.getString(28));
			location.setStatus(rs.getString(29));
			location.setBalance(rs.getDouble(30));
			locList.add(location);
		}
		System.out.println("Query is: "+queryGetLocationToedit);
	} catch (SQLException e) {
		e.printStackTrace();
	}			
	
		return location;		
	}
	
	// default method to fetch the list of all locations:---
	
	public List defaultSearchLocation(Location loc){
		List locList = new ArrayList();
		Location location;
		//String query1 = getWhereClause(loc);
		
		String query = "SELECT LocationID, LocationCode, Name, Category, Address, Block, District, State, Country, LandArea, LandTerm, LandType, RunningFeet, CoveredArea, RegisteredOnName,RegistrationNo, " +
					"RegistrationDate, SubRegistrar, EstimatedValue, StampExpenditure, OtherExpenditure, RegistryHolder, RegistryCopy, BuildingMap, Canteen, Landmark, DistanceFromMainRoad, ResponsiblePerson, Status, TotalBalance FROM location where Status='Approved'";
		try {
			con=lmDB.getDBConnection();
			ps = con.prepareStatement(query);			
			rs = ps.executeQuery();
			while(rs.next()){
				location = new Location();
				location.setLocationID(rs.getString(1));
				location.setLocationCode(rs.getString(2));
				location.setName(rs.getString(3));
				location.setCategory(rs.getString(4));
				location.setAddress(rs.getString(5));
				location.setBlock(rs.getString(6));
				location.setDistrict(rs.getString(7));
				location.setState(rs.getString(8));
				location.setCountry(rs.getString(9));
				location.setLandarea(rs.getString(10));
				location.setLandterm(rs.getString(11));
				location.setLandtype(rs.getString(12));
				location.setRunningft(rs.getDouble(13));
				location.setCoveredarea(rs.getString(14));
				location.setRegisteredname(rs.getString(15));
				location.setRegisterationno(rs.getString(16));
				location.setRegistereddate("2012-12-10");
				location.setSubregistrar(rs.getString(18));
				location.setEstvalue(rs.getDouble(19));
				location.setStmpexp(rs.getDouble(20));
				location.setOtherexp(rs.getDouble(21));
				location.setRegholder(rs.getString(22));
				location.setRegcopy(rs.getString(23));
				location.setBuildingmap(rs.getString(24));
				location.setCanteenOption(rs.getString(25));
				location.setLndmark(rs.getString(26));
				location.setDistance(rs.getString(27));
				location.setResponsible(rs.getString(28));
				location.setStatus(rs.getString(29));
				location.setBalance(rs.getDouble(30));
				locList.add(location);
			}
			System.out.println("Query is: "+query);
		} catch (SQLException e) {
			e.printStackTrace();
		}			
		return locList;
	}

	
	public List searchToApproveLocation(Location loc){
		List locList = new ArrayList();
		Location location;
		//String query1 = getWhereClause(loc);
		
		String query = "SELECT LocationID, LocationCode, Name, Category, Address, Block, District, State, Country, LandArea, LandTerm, LandType, RunningFeet, CoveredArea, RegisteredOnName,RegistrationNo, " +
					"RegistrationDate, SubRegistrar, EstimatedValue, StampExpenditure, OtherExpenditure, RegistryHolder, RegistryCopy, BuildingMap, Canteen, Landmark, DistanceFromMainRoad, ResponsiblePerson, Status, TotalBalance FROM location where Status='Initiated'";
		try {
			con=lmDB.getDBConnection();
			ps = con.prepareStatement(query);			
			rs = ps.executeQuery();
			while(rs.next()){
				location = new Location();
				location.setLocationID(rs.getString(1));
				location.setLocationCode(rs.getString(2));
				location.setName(rs.getString(3));
				location.setCategory(rs.getString(4));
				location.setAddress(rs.getString(5));
				location.setBlock(rs.getString(6));
				location.setDistrict(rs.getString(7));
				location.setState(rs.getString(8));
				location.setCountry(rs.getString(9));
				location.setLandarea(rs.getString(10));
				location.setLandterm(rs.getString(11));
				location.setLandtype(rs.getString(12));
				location.setRunningft(rs.getDouble(13));
				location.setCoveredarea(rs.getString(14));
				location.setRegisteredname(rs.getString(15));
				location.setRegisterationno(rs.getString(16));
				location.setRegistereddate("2012-12-10");
				location.setSubregistrar(rs.getString(18));
				location.setEstvalue(rs.getDouble(19));
				location.setStmpexp(rs.getDouble(20));
				location.setOtherexp(rs.getDouble(21));
				location.setRegholder(rs.getString(22));
				location.setRegcopy(rs.getString(23));
				location.setBuildingmap(rs.getString(24));
				location.setCanteenOption(rs.getString(25));
				location.setLndmark(rs.getString(26));
				location.setDistance(rs.getString(27));
				location.setResponsible(rs.getString(28));
				location.setStatus(rs.getString(29));
				location.setBalance(rs.getDouble(30));
				locList.add(location);
			}
			System.out.println("Query is: "+query);
		} catch (SQLException e) {
			e.printStackTrace();
		}			
		return locList;
	}
	
	// to fetch the state list from db...
	public List<State> getStateList(){
		List<State> stateList = new ArrayList<State>();
		State state;
		//String query1 = getWhereClause(loc);
		
		String query = "SELECT staid, stanam, stamodon, stacrton, staactsts from tbsta";
		try {
			con=lmDB.getDBConnection();
//			Beanvalue bv;
			
			ps = con.prepareStatement(query);			
			rs = ps.executeQuery();
			while(rs.next()){
				state = new State();
				state.setStaid(rs.getString(1));
				state.setStanam(rs.getString(2));
				state.setStamodon(rs.getString(3));
				state.setStacrton(rs.getString(4));
				state.setStaactsts(rs.getString(5));
				
				stateList.add(state);
			}
			System.out.println("Query is: "+query);
		} catch (SQLException e) {
			e.printStackTrace();
		}			
		return stateList;
	}
	
	public List<District> getDstList(String stateName){
		List<District> dstList = new ArrayList<District>();
		State state = new State();
		String queryState = "SELECT staid, stanam, stamodon, stacrton, staactsts from tbsta where stanam= '"+stateName+"'";
		try{
			con=lmDB.getDBConnection();
			ps = con.prepareStatement(queryState);			
			rs = ps.executeQuery();
			while(rs.next()){
				state = new State();
				state.setStaid(rs.getString(1));
				state.setStanam(rs.getString(2));
				state.setStamodon(rs.getString(3));
				state.setStacrton(rs.getString(4));
				state.setStaactsts(rs.getString(5));
			}
		}
		 catch (SQLException e) {
				e.printStackTrace();
			}	
		
		District district;
		//String query1 = getWhereClause(loc);
		String query = "SELECT dstid, dstnam, dstmodon, dstcrton, dststaid, dstactsts from tbdst where dststaid='"+state.getStaid()+"'";
		try {
			con=lmDB.getDBConnection();
//			Beanvalue bv;
			
			ps = con.prepareStatement(query);			
			rs = ps.executeQuery();
			while(rs.next()){
				district = new District();
				district.setDstid(rs.getString(1));
				district.setDstnam(rs.getString(2));
				district.setDstmodon(rs.getString(3));
				district.setDstcrton(rs.getString(4));
				district.setDststaid(rs.getString(5));
				district.setDstactsts(rs.getString(6));
				dstList.add(district);
			}
			System.out.println("Query is: "+query);
		} catch (SQLException e) {
			e.printStackTrace();
		}			
		return dstList;
	}
	
	
}
	
/*	String locCode = loc.getLocationCode();
	String name = loc.getName();
	String category = loc.getCategory();
	String block = loc.getBlock();
	String district = loc.getDistance();
	String state = loc.getState();
	String country = loc.getCountry();
	List locations = new ArrayList();
	String query=null;
		if((locCode!=null || locCode!="") && (name!=null || name!="") && (category!=null || category!="") && (block!=null || block!="") && (district!=null || district!="")
				&& (state!=null || state!="") && (country!=null || country!="") ){
			query = "LOCATIONCODE="+locCode+"and name="+name+"and category="+category+"and block="+block+"and district"+district+
					"and state="+state+"and country="+country+";";}
		else if((name!=null || name!="") && (category!=null || category!="") && (block!=null || block!="")&& (district!=null || district!="")
					&& (state!=null || state!="") && (country!=null || country!="") ){
				query =  "name="+name+"and category="+category+"and block="+block+"and district"+district+
						"and state="+state+"and country="+country+";";
		}
		else if((category!=null || category!="") && (block!=null || block!="")&& (district!=null || district!="")
						&& (state!=null || state!="") && (country!=null || country!="") ){
					//query = "SELECT FormID, LocationID, Amount, Reason, ItemPurchased, TransactionDate, ReturnDate, InterestAmount, PersonID, Narration, TransactionType, ModeOfPayment, TransactionAuthorizerID, Status FROM ACCOUNT  where FormID=?";
					query =  "category="+category+"and block="+block+"and district"+district+
							"and state="+state+"and country="+country+";";	
		}
		else if((block!=null || block!="")&& (district!=null || district!="")
				&& (state!=null || state!="") && (country!=null || country!="") ){
			query =  "block="+block+"and district"+district+
					"and state="+state+"and country="+country+";";
		}
		else if((district!=null || district!="")&&(state!=null || state!="") && (country!=null || country!="") ){
			query =  "district"+district+
					"and state="+state+"and country="+country+";";
		}
		else if((state!=null || state!="") && (country!=null || country!="") ){
			query =  "state="+state+"and country="+country+";";
		}
		else if((country!=null || country!="") ){
			query =  "country="+country+";";
		}
	
		return query;
		}*/
